package com.ruoyi.web.controller.business;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BCompany;
import com.ruoyi.system.domain.vo.BCompanyVo;
import com.ruoyi.system.service.BCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;


/**
 * 药企管理
 * @author yangxz
 **/
@RestController
@RequestMapping("/business/company")
public class CompanyController extends BaseController{

    @Autowired
    BCompanyService companyService;

    /**
     * 获取药企列表
     */
//    @PreAuthorize("@ss.hasPermi('dict:company:list')")
    @PreAuthorize("@ss.hasRole('qygl')")
    @GetMapping("/list")
    public TableDataInfo list(BCompany company)
    {
        startPage();
        List<BCompanyVo> list = companyService.selectCompanyList(company);
        return getDataTable(list);
    }

    /**
     * 根据药企Id获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('dict:company:query')")
    @PreAuthorize("@ss.hasRole('qygl')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable Long companyId) {
        BCompanyVo companyVo = companyService.selectCompanyById(companyId);
        return success(companyVo);
    }

    /**
     * 新增药企
     */
//    @PreAuthorize("@ss.hasPermi('dict:company:add')")
    @PreAuthorize("@ss.hasRole('qygl')")
    @Log(title = "新增药企", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BCompanyVo companyVo)
    {
        return toAjax(companyService.saveVo(companyVo));
    }

    /**
     * 修改药企
     */
//    @PreAuthorize("@ss.hasPermi('dict:company:edit')")
    @PreAuthorize("@ss.hasRole('qygl')")
    @Log(title = "修改药企", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BCompanyVo companyVo)
    {
        return toAjax(companyService.updateVo(companyVo));
    }

    /**
     * 删除药企
     */
//    @PreAuthorize("@ss.hasPermi('dict:company:remove')")
    @PreAuthorize("@ss.hasRole('qygl')")
    @Log(title = "删除药企", businessType = BusinessType.DELETE)
    @DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds)
    {
        return toAjax(companyService.deleteCompanyByIds(companyIds));
    }

}
